package com.easytodo;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;
import com.easytodo.entity.Item;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ItemInfo  extends AppCompatActivity {

    EditText title;
    EditText need;
    EditText importance;
    EditText notice;
    EditText path;
    TextView deadline;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.iteminfo);
        String id=getIntent().getStringExtra("id");
        title=findViewById(R.id.name);
        need=findViewById(R.id.need);
        importance=findViewById(R.id.importance);
        notice=findViewById(R.id.notice);
        path=findViewById(R.id.path);
        deadline=findViewById(R.id.deadline);

        getData(id);
    }
    public void getData(String id){
        Server.getItem(id, new ParsedRequestListener<Item>() {
            @Override
            public void onResponse(Item response) {
                title.setText(response.getTitle());
                need.setText(String.format("%dmin needed",response.getNeedTime()/(1000*60)));
                importance.setText(response.getImportance());
                notice.setText(response.getRemarks());
                path.setText(response.getPath());
                SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                deadline.setText(formatter.format(new Date(response.getDeathLine())));
            }

            @Override
            public void onError(ANError anError) {

            }
        });
    }
}
